package servlets;

import java.io.IOException;

import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import business.Produto;
import business.Venda;

import dao.repositorioProduto;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;



public class ServletRelatorio extends HttpServlet implements Servlet 
{
	
	protected void doGet(HttpServletRequest request, 
			HttpServletResponse response) 
			throws ServletException, IOException 
	{
		doPost(request,response);
	}
	
	protected void doPost(HttpServletRequest request, 
				  HttpServletResponse response) 
				  throws ServletException, IOException
	{
		String comando = request.getParameter("comando");
		
		if (comando == null)
		{
			response.sendRedirect("relatorios.jsp");
		}		
		else if (comando.equals("gerarProd"))
		{
			dao.repositorioProduto rep = new repositorioProduto();
			JasperPrint relat;
			

			try {
				relat = rep.gerar();
				JasperViewer.viewReport(relat, false);
			} catch (RuntimeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	
		}
	}
}














